package se.webbzon.boltzmann.minigame.sandbox;

import java.awt.Image;

import se.webbzon.oschi01.textureset.Texture3D;
import se.webbzon.oschi01.worldcamera.WorldCameraPane;

public class SandBoxIcon {
	
	// The image icon of this sand box icon 
	private final Image icon;
	
	// The width and the height of the sand box icon
	private int width, height;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public SandBoxIcon(Texture3D texture, int width, int height) {
		this(texture.getImage(),width,height);
	}
	
	public SandBoxIcon(Image image, int width, int height) {
		icon = image;
		this.width = width;
		this.height = height;
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Returns the width of the sand box icon. **/
	public int getWidth() {
		return width;
	}

	/** Returns the height of the sand box icon. **/
	public int getHeight() {
		return height;
	}
	
	/** Draws the sand box icon onto the provided world camera pane at the
	 * given position. **/
	public void drawIcon(WorldCameraPane pane, int x, int y) {
		drawIcon(pane,x,y,-1,-1);
	}
	
	/** Draws the sand box icon onto the provided world camera pane at the
	 * given position. **/
	public void drawIcon(WorldCameraPane pane, int x, int y, int maxWidth, int maxHeight) {
		if (width == -1)
			width = icon.getWidth(pane.getImageObserver());
		if (height == -1)
			height = icon.getHeight(pane.getImageObserver());
		int w, h;
		if (width > maxWidth)
			w = maxWidth;
		else
			w = width;
		if (height > maxHeight)
			h = maxHeight;
		else
			h = height;
		int xd = x - w/2, yd = y - h/2;
		pane.drawImage(icon, xd, yd, w, h);
	}

}
